#!/bin/sh

if [ "$1" = "autoconf" ]; then
	if which apcaccess > /dev/null; then
		echo yes
		exit 0
	else
		echo no
		exit 0
	fi
fi

if [ "$1" = "config" ]; then
	cat <<EOF
graph_title UPS Voltages
graph_category sensors
graph_vlabel Volts
graph_args --base 1000
graph_info UPS Voltages
linev.label Current input line voltage
nominv.label Nominal input line voltage
battv.label Current battery charge voltage
nombattv.label Nominal battery voltage
EOF
	exit 0
fi

apcaccess -u | awk '
/:/ {
	a[tolower($1)] = $3
}
END {
	print "linev.value",    a["linev"]
	print "nominv.value",   a["nominv"]
	print "battv.value",    a["battv"]
	print "nombattv.value", a["nombattv"]
}
'
